package com.ruoyi.mall.controller;

import java.util.List;
import com.ruoyi.mall.entity.MallMembersPackage;
import com.ruoyi.mall.service.IMallMembersPackageService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会员优惠中间表Controller
 * 
 * @author ruoyi
 * @date 2020-05-25
 */
@Controller
@RequestMapping("/mall/membersPackage")
public class MallMembersPackageController extends BaseController
{
    private String prefix = "mall/membersPackage";

    @Autowired
    private IMallMembersPackageService mallMembersPackageService;

    @RequiresPermissions("mall:membersPackage:view")
    @GetMapping()
    public String memberspackage()
    {
        return prefix + "/package";
    }

    /**
     * 查询会员优惠中间表列表
     */
    @RequiresPermissions("mall:membersPackage:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MallMembersPackage mallMembersPackage)
    {
        startPage();
        List<MallMembersPackage> list = mallMembersPackageService.selectMallMembersPackageList(mallMembersPackage);
        return getDataTable(list);
    }

    /**
     * 导出会员优惠中间表列表
     */
    @RequiresPermissions("mall:membersPackage:export")
    @Log(title = "会员优惠中间表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MallMembersPackage mallMembersPackage)
    {
        List<MallMembersPackage> list = mallMembersPackageService.selectMallMembersPackageList(mallMembersPackage);
        ExcelUtil<MallMembersPackage> util = new ExcelUtil<MallMembersPackage>(MallMembersPackage.class);
        return util.exportExcel(list, "package");
    }

    /**
     * 新增会员优惠中间表
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存会员优惠中间表
     */
    @RequiresPermissions("mall:membersPackage:add")
    @Log(title = "会员优惠中间表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MallMembersPackage mallMembersPackage)
    {
        return toAjax(mallMembersPackageService.insertMallMembersPackage(mallMembersPackage));
    }

    /**
     * 修改会员优惠中间表
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        MallMembersPackage mallMembersPackage = mallMembersPackageService.selectMallMembersPackageById(id);
        mmap.put("mallMembersPackage", mallMembersPackage);
        return prefix + "/edit";
    }

    /**
     * 修改保存会员优惠中间表
     */
    @RequiresPermissions("mall:membersPackage:edit")
    @Log(title = "会员优惠中间表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MallMembersPackage mallMembersPackage)
    {
        return toAjax(mallMembersPackageService.updateMallMembersPackage(mallMembersPackage));
    }

    /**
     * 删除会员优惠中间表
     */
    @RequiresPermissions("mall:membersPackage:remove")
    @Log(title = "会员优惠中间表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(mallMembersPackageService.deleteMallMembersPackageByIds(ids));
    }
}
